Soru & Cevap

ExpandableListView child itemlere tıklama? ...

13.01.2015 - 09:35

Bu kodları hazır bir yerden aldım.Burda childlara tıklandığında ekranda childların ismi çıkıyor ben bunun yerine yeni bir sayfaya gitmesini istiyorum yardımcı olurmusunuz. Şimdiden Teşekkürler 

[code][/code]

package com.dpFaa.acikogretim;

import java.util.ArrayList;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.CheckedTextView;
import android.widget.TextView;
import android.widget.Toast;


public class MyExpandableAdapter extends BaseExpandableListAdapter {

    private Activity activity;
    private ArrayList<Object> childtems;
    private LayoutInflater inflater;
    private ArrayList<String> parentItems, child;
    

    public MyExpandableAdapter(ArrayList<String> parents, ArrayList<Object> childern) {
        this.parentItems = parents;
        this.childtems = childern;
    }

    public void setInflater(LayoutInflater inflater, Activity activity) {
        this.inflater = inflater;
        this.activity = activity;
    }

    
    @Override
    public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        
        child = (ArrayList<String>) childtems.get(groupPosition);
        
        TextView textView = null;
        
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.group, null);
        }
        
        textView = (TextView) convertView.findViewById(R.id.textView1);
        textView.setText(child.get(childPosition));
        
        convertView.setOnClickListener(new OnClickListener() {
            
            @Override
            public void onClick(View view) {
                Toast.makeText(activity, child.get(childPosition),
                        Toast.LENGTH_SHORT).show();
            }
        });
        
        return convertView;
    }
    
    
    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.row, null);
        }
        
        ((CheckedTextView) convertView).setText(parentItems.get(groupPosition));
        ((CheckedTextView) convertView).setChecked(isExpanded);
        
        return convertView;
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return null;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return 0;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return ((ArrayList<String>) childtems.get(groupPosition)).size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return null;
    }

    @Override
    public int getGroupCount() {
        return parentItems.size();
    }

    @Override
    public void onGroupCollapsed(int groupPosition) {
        super.onGroupCollapsed(groupPosition);
        
    }

    @Override
    public void onGroupExpanded(int groupPosition) {
        super.onGroupExpanded(groupPosition);
    }

    @Override
    public long getGroupId(int groupPosition) {
        return 0;
    }

    

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return false;
    }

}

26 Görüntülenme

2 Cevap

Sitedeki sorulara cevap verebilmek için giriş yapın ya da üye olun.

picture-1372-1408467635.jpg
ahmtbrk
13.01.2015 - 10:17

child.get(childPosition) sana o an tıklanan child elementini verir ona göre işlem yapabilirsin if koyup içeriye.

picture-1372-1408467635.jpg
ahmtbrk
13.01.2015 - 09:54

Toast.makeText(activity, child.get(childPosition),
                        Toast.LENGTH_SHORT).show();

yazan kısımda herhangi bir iteme tıklandığında tetiklenen event mevcut.

oraya şunu yazacaksın.

Intent intent = new Intent(activity,HedefSayfa.Class);

activity.startActivity(intent);

Furkan
13.01.2015 - 10:13
peki şuan benim 4 adet grubum var var hepsininde childları hangisinin hangisi olduğunu nasıl belirtirim?